<?php
/**
 * 简历解析 Logic
 */

namespace app\common\logic\package;

use think\Exception;

/**
 *  压缩包
 * Class ZipArchiveLogic
 * @package app\common\logic
 */
class BaseArchiveLogic {
    private static $interion;
    protected $dir;
    protected $class;
    public function __construct()
    {
    }
    public static function make($ext){
        if(!self::$interion instanceof self){
            $class = $ext == 'zip'?ZipArchiveLogic::class:RarArchiveLogic::class;
            self::$interion = new $class();
        }
        return self::$interion;
    }

    protected function mkdir($dir){
        if(!is_dir($dir)) {
            //检测文件是否存在
            mkdir($dir,0777);
            //如果文件不存在，则新建
        }
        $this->dir = $dir;
        return $this;
    }
    public function getFiles($path=''){
        $path || $path = $this->dir;
        $files = scandir($path);
        $result = [];
        foreach ($files as $file) {
            if ($file != '.' && $file != '..') {
                if (is_dir($path . '/' . $file)) {
                    $result = array_merge($result,$this->getFiles($path . '/' . $file));
                } else {
                    $result[] = $path.'/'.$file;
                }
            }
        }
        return $result;
    }
    public function close(){
//        try{rmdirs($this->dir);}catch(Exception $e){}
        $this->class->close();
        return $this;
    }
}